<?php

namespace app\common\model;

use think\Model;
class Tokenlog extends Model
{
    // 表名
    protected $name = 'tokenlog';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    
    // 追加属性
    protected $append = [
        'status_text',
        'createtime',
    ];
    

    
    public function getStatusList()
    {
        return ['wait' => __('Status wait'),'finish' => __('Status finish')];
    }     

    public function getCreatetimeAttr($value='')
    {
        return date('Y-m-d H:i:s',$value);
    }


    public function getStatusTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['status'];
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function touser()
    {
        return $this->belongsTo('User', 'touser_id', 'id', [], 'LEFT')->field('id,username')->setEagerlyType(0);
    }

}
